<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="content">收藏</block>
		</cu-custom>
		<view class="padding">
			<view class="navList bg-white radius-xl padding-xs">
				<u-sticky bgColor="#fff">
					<u-tabs :list="navList" @click="navClick" keyName="name" :scrollable="false"
						lineColor="var(--theme-color)" :activeStyle="{ color: 'var(--theme-color)', fontWeight: 'bold' }">
					</u-tabs>
				</u-sticky>
			</view>
		</view>
		<view class="list padding" v-if="list.length > 0">
			<template v-if="search.action==='service'">
				<view class="radius-xl item padding-sm bg-white" v-for="(item, index) in list" :key="index"
					:class="list.length - 1 != index ? 'solid-bottom' : ''">
					<image :src="item.thumb" mode="" class="img"></image>
					<view class="probox">
						<view class="title text-bold text-black">
							<text>{{ item.title }}</text>
							<view class="text-sm text-right cost text-red">
								<text class="text-bold">¥</text>
								<text class="text-lg text-bold">{{ item.price }}</text>
							</view>
						</view>
						<view class="text-gray text-sm">{{ item.tips }}</view>
						<!-- <view class="cu-tag sm margin-bottom-sm">
								{{item.tag}}
							</view> -->
						<view class="price flex flex-wrap">
							<view class="time basis-lg text-sm">
								<text class="cuIcon-timefill text-lg themeColor"></text>
								<text class="padding-left-mn">{{ item.service_duration }}分钟</text>
								<text class="cuIcon-tagfill text-lg padding-left-xs themeColor"></text>
								<text class="padding-left-mn">{{ item.sales_num }}人选择</text>
							</view>
							<view class="basis-sm text-right"
								@click="$utils.$page.open('/pages/project/details?id=' + item.id)">
								<button class="cu-btn bg-green sm round">立即选择</button>
							</view>
						</view>
					</view>
				</view>
			</template>
			<template v-else-if="search.action==='shop'">
				<view class="radius-xl item padding-sm bg-white" v-for="(item, index) in list" :key="index"
					:class="list.length - 1 != index ? 'solid-bottom' : ''">
					<image :src="item.logo" mode="" class="img"></image>
					<view class="probox">
						<view class="title text-bold text-black">
							<text>{{ item.title }}</text>
						</view>
						<view class="text-gray text-sm">{{ item.city }} {{ item.area }} {{ item.street }}</view>
						<view class="price flex flex-wrap">
							<view class="time basis-lg text-sm">
							</view>
							<view class="basis-sm text-right"
								@click="$utils.$page.open('/pages/mch/details?id=' + item.id)">
								<button class="cu-btn bg-green sm round">查看</button>
							</view>
						</view>
					</view>
				</view>
			</template>
		</view>
		<emptyData v-else type="notLog" top="10" text="暂无收藏"></emptyData>

		<loading v-if="pageLoading" />
	</view>
</template>

<script>
let debounceGetList;
export default {
	data() {
		return {
			pageLoading: false,
			search: {
				page: 1,
				keywords: '',
				action:'service'
			},
			navList: [
				{ name: '服务', scene: 'service' },
				{ name: '门店', scene: 'shop' },
			],
			list: []
		};
	},
	onLoad() {
		this.getList();
	},
	onReachBottom() {
		this.search.page++;
		this.getList();
	},
	methods: {
		navClick(e) {
			this.search.action = e.scene;
			this.search.page = 1;
			this.list = [];
			this.getList();
		},
		getList() {
			if (this.pageLoading) return;
			this.pageLoading = true;
			this.$utils.$api.Collect.serviceList(this.search).then(data => {
				this.list = [...this.list, ...data.data];
			}).finally(() => {
				this.pageLoading = false;
			});
		},
		collect(item, index) {
			this.$utils.$api.Collect.service(item.id).then((data) => {
				this.list.splice(index, 1);
			}).catch(err => {
				this.$utils.$message.error(err.msg);
			})
		}
	},
}
</script>
<style lang="less" scoped>
.list {
	.item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
		height: 180rpx;

		// background-color: #fea1a5;
		.img {
			width: 170rpx;
			height: 130rpx;
			border-radius: 10upx;
		}

		.probox {
			width: 70%;
			height: 130rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.title {
				display: flex;
				justify-content: space-between;
				align-items: baseline;

				.cost {
					width: 125upx;
				}
			}

			.price {
				align-items: center;
			}
		}
	}
}
</style>
